# This file is part of trytond-fyireporting module for Tryton. 
# The COPYRIGHT file at the top level of this repository contains 
# the full copyright notices and license terms.

from trytond.pool import Pool
from trytond.transaction import Transaction
from trytond.model import ModelView, fields
from trytond.wizard import Wizard, StateView, StateAction, StateTransition, \
    Button
from trytond.modules.fyireporting.fyireporting import FyireportingReport

__all__ = ['PrintResGroupStart', 'PrintResGroup', 'ResGroupReport']

class PrintResGroupStart(ModelView):
    'Print Groups'
    __name__ = 'fyireporting.print_res_group.start'

    output_type = fields.Selection([
            ('pdf', 'PDF'),
            ('xlsx', 'XLSX'),
            ('csv', 'CSV'),
            ('html', 'HTML'),
            ('xml', 'XML'),
            ], 'Output Type', required=True)

    @staticmethod
    def default_output_type():
        return 'pdf'

class PrintResGroup(Wizard):
    'Print Groups'
    __name__ = 'fyireporting.print_res_group'
    start = StateView('fyireporting.print_res_group.start',
        'fyireporting.print_res_group_start_view_form', [
            Button('Cancel', 'end', 'tryton-cancel'),
            Button('Print', 'print_', 'tryton-print', default=True),
            ])
    print_ = StateAction('fyireporting.report_res_group')

    def do_print_(self, action):
        data = {
            'output_type': self.start.output_type,
            }
        return action, data

    def transition_print_(self):
        return 'end'


class ResGroupReport(FyireportingReport):
    __name__ = 'fyireporting.res_group'

    @classmethod
    def execute(cls, ids, data):
        data["str_where"] = "id<>-1"
        if ids:
            data["str_where"] = ""
            for i in ids:
                if data["str_where"] == "":
                    data["str_where"] = " id=" + str(i)
                else: 
                    data["str_where"] = data["str_where"] + " OR id=" + str(i)

        return super(ResGroupReport, cls).execute(ids, data)















